﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace ConsoleApp.拦截器
{
    public class OrderInterceptContextFactory
    {
        //共享数据

        private readonly Lazy<BlackPhone[]> _lazyBlackPhones;

        public OrderInterceptContextFactory()
        {
            _lazyBlackPhones = new Lazy<BlackPhone[]>(()=> GetAllBlackPhones().ToArray(),true);
        }

        private IEnumerable<BlackPhone> GetAllBlackPhones()
        {
            return DBData.GetBlackPhonesDBData();
        }

        /// <summary>
        /// 创建拦截上下文
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public OrderInterceptContext CreateContext(OrderInterceptInput input)
        {
            return new OrderInterceptContext(input, this);
        }

        public BlackPhone[] GetBlackPhones()
        {
            return _lazyBlackPhones.Value;
        }

    }
}
